package com.zzyang.c2c.social.govern.report.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * druid数据源配置
 *
 * @author zhuoziyang
 * @date 2021/2/13 0:05
 */
@Configuration
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
public class DruidDataSourceConfig {

    @Autowired
    private DataSourceProperties dataSourceProperties;

    @Bean
    @Primary
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setUsername(dataSourceProperties.determineUsername());
        dataSource.setPassword(dataSourceProperties.determinePassword());
        dataSource.setUrl(dataSourceProperties.determineUrl());
        dataSource.setDriverClassName(dataSourceProperties.determineDriverClassName());
        return dataSource;
    }

}
